home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Snippets / numofcolors / numofcolors.c next >
Encoding:
C/C++ Source or Header  |  1994-05-07  |  2.4 KB  |  81 lines  |  [TEXT/R*ch]

  1. /***********************************************************
  2.  
  3.         This has worked for me, altough it took a lot of
  4.         investigative coding to discover...
  5.  
  6.         short           getNumberOfColors( void )
  7.                 Returns the number of colors the monitor is set to.
  8.                 NOTE: This only checks for up to 256 colors.  If you
  9.                         have 24-bit capability and figure out how
  10.                         to check for that also, post it [and mail it
  11.                         to me :-) ]
  12.  
  13.                         4/19/94  by Paul Rademacher
  14.                                 Dept. of Computer Science
  15.                                 West Virginia University
  16.                                 paulr@cs.wvu.edu
  17.  
  18. ***********************************************************/
  19.  
  20. #include <GestaltEqu.h>
  21.  
  22. #define         kColorModeBW                    128
  23. #define         kColorModeColor4                129
  24. #define         kColorModeColor16               130
  25. #define         kColorModeColor256              131
  26.  
  27. short           getNumberOfColors( void );
  28.  
  29. short           getNumberOfColors( void )
  30. {
  31.         GDHandle        device;
  32.         short           mode;
  33.         short           quickDrawVersion;
  34.         long            feature;
  35.         OSErr           err;
  36.  
  37.         /* Here we get the QuickDraw version of this machine */
  38.  
  39.         if ( err = Gestalt( gestaltQuickdrawVersion, &feature ) == noErr )
  40.         {
  41.                 quickDrawVersion = feature;
  42.  
  43.                 if ( quickDrawVersion < gestalt8BitQD )
  44.                 {
  45.                         return( 2 );
  46.  
  47.                         return;
  48.                 }
  49.         }
  50.         else
  51.         {
  52.                 /* There was an error with Gestalt() - we'll asume 2 colors */
  53.  
  54.                 return( 2 );
  55.         }
  56.  
  57.         device = GetGDevice();
  58.  
  59.         mode =  ( **device ).gdMode;
  60.  
  61.         switch ( mode )
  62.         {
  63.                 case kColorModeBW:
  64.                         return( 2 );
  65.                         break;
  66.                 case kColorModeColor4:
  67.                         return( 4 );
  68.                         break;
  69.                 case kColorModeColor16:
  70.                         return( 16 );
  71.                         break;
  72.                 case kColorModeColor256:
  73.                         return( 256 );
  74.                         break;
  75.                 default:        /* Does not check for >256 colors... */
  76.                         return( 2 );
  77.                         break;
  78.         }
  79. }
  80.  
  81.